<?php

/**
 * This scripts generates a JSDuck config file based on some PHP variables
 * 
 * @author Steffen Brem <steffenbrem@gmail.com>
 */

$config['--title']			= 'Cube Framework';

$basePath 		= '../trunk/library/';
$extensions 	= array('.php');

// ==================================================================================================================

$config['--'] = array();

$basePath = rtrim($basePath, '/');

if (!file_exists($basePath))
{
	die("Base directory '" . $basePath . "' does not exist.");
}

/**
 * Get file file list
 * 
 * @param {String} $path
 * @param {Int} $level
 */
function getFileList($path, $level = 1) 
{
    $arrFiles = scandir($path);
	
    $arrFileList = array();
    $total = count($arrFiles);
	
    for ($i = 0; $i < $total; $i++) 
    {
        if($arrFiles[$i] != "." && $arrFiles[$i] != "..") 
        {
            if(is_dir($path."/".$arrFiles[$i])) 
            {
                if($level > 99)
				{
                	return $arrFileList;
				}
                
                $arrFileList = array_merge($arrFileList, getFileList($path."/".$arrFiles[$i],$level+1));
            } 
            else 
            {
                $arrFileList[] = $path."/".$arrFiles[$i];
            }
        }
    }
	
    return($arrFileList);
}

$config['--'] = getFileList($basePath);

echo '<pre>', print_r($config);

$handle = fopen("config.json", "w+");
fwrite($handle, json_encode($config));
fclose($handle);
